package org.wangblue.invoker;

import org.wangblue.command.Command;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

/**
 * @Description: 服务员
 * @Author: WangBlue
 * @Create: 2024-09-24 10:30
 * @Version: 1.0
 **/

public class Waiter1 {
    private final ArrayList<Command> commands = new ArrayList<>();
    // 设置订单
    public void setOrder(Command command) {
        String className = command.getClass().getSimpleName();// 获取 command 对象所属类的简单类名
        if (className.equals("BakeMutterCommand")){
            System.out.println("考羊肉没有啦，请重新点其他的食品");
        }else{
            commands.add(command);
        }
    }
    // 取消订单
    public void cancelOrder(Command command) {
        commands.remove(command);
        String className = command.getClass().getSimpleName();
        System.out.println("取消订单 " + className +  " " +  getNowTime());
    }

    // 执行通知
    public void notifyCommand(){
        for (Command command : commands){
            command.execute();
        }
    }

    protected String getNowTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(System.currentTimeMillis());
           }
}
